package com.ly.hotel.spainterface.nm;

import android.content.Context;
import android.util.Log;
import android.view.View;

import androidx.recyclerview.widget.GridLayoutManager;

/**
 * Created by SHUBEN on 2018/3/11.
 */

public class FocusGridLayoutManager extends GridLayoutManager {

    public FocusGridLayoutManager(Context context, int spanCount) {
        super(context, spanCount);
    }

    @Override
    public View onInterceptFocusSearch(View focused, int direction) {
        Log.i("fuck","onInterceptFocusSearch , focused = "+focused +" direction = "+direction);
        int span = getSpanCount();
        int count = getItemCount();
        int fromPos = getPosition(focused);
        Log.i("fuck",span + ":" + count + ":" + fromPos);
        switch (direction) {
            case View.FOCUS_UP:
                fromPos = (fromPos - span);
                break;
            case View.FOCUS_DOWN:
                fromPos = (fromPos + span);
                break;
            case View.FOCUS_RIGHT:
                fromPos++;
                break;
            case View.FOCUS_LEFT:
                fromPos--;
                break;
        }

        Log.i("fuck", "onInterceptFocusSearch , fromPos = "+fromPos + " count = " + count+" span = "+span);
        if(fromPos < 0) {
            return focused;
        } else if(fromPos >= count) {
            return focused;
        } else {
            return findViewByPosition(fromPos);
//            return getChildAt(fromPos);
        }
    }
}
